package com.josework.springhelloworld.controller;

import com.josework.springhelloworld.AjaxResponse;
import com.josework.springhelloworld.base.BaseResponse;
import com.josework.springhelloworld.dto.PageResult;
import com.josework.springhelloworld.dto.user.UserEditParams;
import com.josework.springhelloworld.dto.user.UserSearchParams;
import com.josework.springhelloworld.dto.user.UserView;
import com.josework.springhelloworld.service.impl.UserServiceImpl;
import lombok.var;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController extends BaseController{

    @Autowired
    private UserServiceImpl userService;

    @PostMapping("/saveorupdate")
//    @ApiOperation("新增编辑")
    public BaseResponse<UserView> saveorupdate(@RequestBody @Valid UserEditParams params) {
        userService.saveOrUpdate(params);
        return ok();
    }

    @GetMapping("/get/{id}")
    public BaseResponse<UserView> getById(@PathVariable("id")Long id){
        UserView user = userService.getUserById(id);
        return ok(user);
    }

    @PostMapping("/search")
//    @ApiOperation("查询列表")
    public BaseResponse<PageResult<UserView>> search(@RequestBody UserSearchParams params) {
        PageResult<UserView> page = userService.findPage(params);
        return ok(page);
    }

    @PostMapping("/delete")
//    @ApiOperation("批量删除")
    public BaseResponse delete(@RequestBody @Valid @NotEmpty(message = "ids can not be empty") List<Long> ids) {
        userService.removeByIds(ids);
        return ok();
    }










}
